package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.activity.ActivityDO;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import jakarta.websocket.server.PathParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: chouh
 * @DateTime: 2025/10/13 0:31
 * @Description:
 */
@Slf4j
@RestController
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/activities/type/{type}")
    public Result queryActivitiesByType(@PathVariable Integer type) {
        log.info("queryActivitiesByType: {}", type);
        List<Activity> activities = activityService.queryActivitiesByType(type);
        return Result.success(activities);
    }

    @PutMapping("/activities")
    public Result updateActivity(@RequestBody Activity activity) {
        log.info("updateActivity:{}",activity);
        activityService.updateActivity(activity);
        return Result.success();
    }

    @GetMapping("/activities/{id}")
    public Result queryActivityById(@PathParam(value = "id") Integer id) {
        log.info("queryActivityById:{}", id);
        Activity activity = activityService.queryActivityById(id);
        return Result.success(activity);

    }

    @PostMapping("/activities")
    public Result addActivity(@RequestBody Activity activity) {
        log.info("添加活动：{}", activity);
        activityService.addActivity(activity);
        return Result.success();
    }

    @DeleteMapping("/activities/{id}")
    public Result deleteActivityBy(@PathVariable Integer id) {
        log.info("deleteActivityBy:{}", id);
        activityService.deleteActivityById(id);
        return Result.success();
    }

    @GetMapping("/activities")
    public Result getActivities(ActivityDTO activityDTO) {
        log.info("getActivities:{}", activityDTO);
        PageResult<ActivityDO> result = activityService.getActivities(activityDTO);
        return Result.success(result);
    }
}
